//
//  MJTabBarController.m
//  foodlist
//
//  Created by HappyMilk 02 on 2017/8/15.
//  Copyright © 2017年 tomi. All rights reserved.
//

#import "MJTabBarController.h"
#import "LoginHeader.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "SearchViewController.h"

#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

#define TABBARIMAGE(string) [[UIImage imageNamed:string] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]


@interface MJTabBarController ()


@end

@implementation MJTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0xcdcdcd)} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HEXCOLOR(0xFD6A62)} forState:UIControlStateSelected];
    
    [self addChildVcWithStoryboardName:@"Main"
                                 title:@"菜谱"
                                  icon:@"tb_h_nol"
                               selIcon:@"tb_h_sel"
                            vcIdentity:@"HomeViewController"];
    
    [self addChildVcWithStoryboardName:@"Main"
                                 title:@"搜索"
                                  icon:@"tb_ser_nol"
                               selIcon:@"tb_ser_sel"
                            vcIdentity:@"SearchViewController"];
    
    [self addChildVcWithStoryboardName:@"Main"
                                 title:@"我的"
                                  icon:@"tb_min_nol"
                               selIcon:@"tb_min_sel"
                            vcIdentity:@"MineViewController"];
    

}

- (void)addChildVcWithStoryboardName:(NSString *)storyboardName
                               title:(NSString *)title
                                icon:(NSString *)icon
                             selIcon:(NSString *)selIcon
                          vcIdentity:(NSString*)vcid
{
    /* 加载名为storyboardName的Storyboard */
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
    
    /* 获取storyboard的InitialViewController 即根控制器*/
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:vcid];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.navigationBarHidden = YES;
    
    UIImage * normalImage = [[UIImage imageNamed:icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage * selectImage = [[UIImage imageNamed:selIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    /* 设置tabbarItem的标题、默认图片以及选中时的图片 */
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title
                                                  image:normalImage
                                          selectedImage:selectImage];
    
    /* 添加子控制器 */
    [self addChildViewController:nav];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
